#include "viaimg.h"
using namespace nVIA;

#define ALIGN4(w)	((((w)*3 + 3) >> 2) << 2)

BOOL	nVIA::CBitmap::Init(int width, int height, int pitch, 
							VIA_COLORFORMAT format)
{
	int y;
	PBYTE pd, ps;

	if (width <= 0 || height <= 0 || pitch <= 0)
		return FALSE;

	m_width = width;
	m_height = height;
	m_pitch = pitch;
	if (m_bufSize < m_height * m_pitch) {
		if (m_bits)
			delete [] m_bits;
		m_bits = new BYTE[m_height * m_pitch];
		m_bufSize = m_height * m_pitch;
	}

// 	switch (format) {
// 	case VIA_CF_BGR:
// 		pd = m_bits;
// 		ps = bits;
// 		for (y = 0; y < height; y++) { 
// 			memcpy(pd, ps, width * 3);
// 			pd += m_pitch;
// 			ps += pitch;
// 		}
// 		break;
// 	default:
// 		return FALSE;
// 	}
	m_format = format;

	memset(&m_biInfo, 0, sizeof(m_biInfo));
	m_biInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	m_biInfo.bmiHeader.biWidth = m_width;
	m_biInfo.bmiHeader.biHeight = m_height;
	m_biInfo.bmiHeader.biPlanes = 1;
	m_biInfo.bmiHeader.biBitCount = 24;
	
	return TRUE;
}

void	CBitmap::Release()
{
	if (m_bits) {
		delete [] m_bits;
		m_bits = NULL;
	}
	m_bufSize = 0;
}